﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
        <ol class="breadcrumb">
    <li><a href="/Home.html">Home</a></li>
    <li><a href="/WebApp/WebApi"> Sanelib WebApp</a></li>
    <li class="active">Member Card</li>
</ol>
    
            <div id="introduction">
                <h1 class="text-left">ControllerApis</h1>
                <h4>MemberCardController</h4>
            </div>
            <div>
                <h3>Class Inherited : SmartApiController</h3>
                <table class="table-condensed table-striped">
                    <tr>
                        <th>Constructor</th>
                        <th>Parameters</th>
                    </tr>
                    <tr>
                        <td class="table-bordered">IUserSession</td>
                        <td class="table-bordered">IMappingEngine</td>
                        <td class="table-bordered">IViewRepository&lt;MemberView&gt;</td>
                    </tr>
                </table>
                <p>Where, IUserSession and IMappingEngine Local Variable are assigned to a Instance Variable form the <b>base</b> of <a href="/WebApp/SmartApi" class="btn-link">SmartApiController</a></p><br />
                <b>IViewRepository&lt;MemberView&gt;</b> is the interface is defined in the Saneli Library where to declare to the methods of the type of generics like a FetchAll, Fetch, GetById, GetByKey, GetForAll, SearchBySpecification for the <b>MemberView</b>
                <ol id="method">
                    <li>
                        <b>Get() :</b>Where the pass as a parameters of the <b>MemberLookUpForm</b>.
                        <pre><code>
public HttpResponseMessage Get(MemberLookupForm form)
{....}
</code></pre>
                        <p>here, MemberLookUpForm get details of the MemberId, TagId, Code into the form object</p>
                        <p>In this method to describe how to used to the IViewRepository and get the key Code and TagId by the GetbyKey() defined in that interface</p>
                        <pre><code>
if (!string.IsNullOrEmpty(form.Code))
{
    var view = _memberViewRepository.GetByKey(Property.Of&lt;MemberView&gt;(x => x.Code), form.Code);
    if (view != null) return Content(Mapper.Map&lt;MemberView, MemberCardResponse&gt;(view));
}
else if (!string.IsNullOrEmpty(form.TagId))
{
    var view = _memberViewRepository.GetByKey(Property.Of&lt;MemberView&gt;(x => x.TagId), form.TagId);
    if (view != null) return Content(Mapper.Map&lt;MemberView, MemberCardResponse&gt;(view));
}
var errors = new ErrorResult();
errors.AddError("TagId or Code", "does not match");
return Content(errors);
</code></pre>
                        <p>here,For the get the Code used to the <b>GetByKey</b> is the <b>IViewRepository&lt;MemberView&gt;</b> mehods and if the view has not a null then the return the content of the mapping between the MemberView and the MemberCardResponse</p>
                        <p>Same is used by the get the TagId</p>
                        <p>ErrorResult is the create a ErrorResult if the not to get any result from the MemberLookupForm </p>
                    </li>
                    <li>
                        <p>
                            <b>Post() :</b>
                            In this to the pass the parameters of the MemberCardRegisterForm
                        </p>
                        <pre><code>
public HttpResponseMessage Post(MemberCardRegisterForm form)
{....}
</code></pre>
                        <p>After in the method of the add the command for the Post the request</p>
                        <pre><code>
var member = _memberViewRepository.GetByKey(Property.Of&lt;MemberView&gt;(x => x.Code), form.Code);
if (member == null)
{
    return Content(new ErrorResult());
}
var command = new RegisterMemberCard
{
    Id = member.Id,
    TagId = form.TagId
};
return ExecuteCommand(command);
}
</code></pre>
                        <p>here, the first the get the member from the MemberView used of the <b>IViewRepository&lt;MemberView&gt;</b></p>
                        <p>after if the member is null then return the content of the <b>ErrorResult</b> otherwise to the return to the ExecuteCommand for the RegisterMemberCard</p>
                    </li>

                </ol>
            </div>
     